﻿using DG.Tweening;
using UnityEngine;

public static class TweenExtension
{
    #region Television电视机

    public static Tween DOOpenHorizontalTelevision(this Transform transform, float Speed = 1, TweenCallback Complete = null, float Delay = 0)
    {
        transform.localScale = Vector3.zero;
        Tweener TweenerY = transform.DOScaleY(1, 0.27f * Speed);
        TweenerY.SetEase(Ease.OutExpo);
        Tweener TweenerX = transform.DOScaleX(1, 0.17f * Speed);
        TweenerX.SetEase(Ease.OutExpo); // 修复：应该是TweenerX而不是TweenerY
        Sequence Answer = DOTween.Sequence();//创建一个tween序列
        Answer.SetDelay(Delay);
        Answer.Insert(0, TweenerX);//这一段应该是不同步执行tween的设置
        Answer.Insert(0.12f * Speed, TweenerY);
        Answer.onComplete = Complete;
        return Answer;
    }

    public static Tween DOCloseHorizontalTelevision(this Transform transform, float Speed = 1, TweenCallback Complete = null, float Delay = 0)
    {
        Tweener TweenerY = transform.DOScaleY(0, 0.27f * Speed);
        TweenerY.SetEase(Ease.OutExpo);
        Tweener TweenerX = transform.DOScaleX(0, 0.17f * Speed);
        TweenerX.SetEase(Ease.OutExpo);
        Sequence Answer = DOTween.Sequence();
        Answer.SetDelay(Delay);
        Answer.Insert(0, TweenerY);
        Answer.Insert(0.12f * Speed, TweenerX);
        Answer.onComplete = Complete;
        return Answer;
    }

    public static Tween DOOpenVerticalTelevision(this Transform transform, float Speed = 1, TweenCallback Complete = null, float Delay = 0)
    {
        transform.localScale = Vector3.zero;
        Tweener TweenerX = transform.DOScaleX(1, 0.27f * Speed);
        TweenerX.SetEase(Ease.OutExpo);
        Tweener TweenerY = transform.DOScaleY(1, 0.17f * Speed);
        TweenerY.SetEase(Ease.OutExpo);
        Sequence Answer = DOTween.Sequence();//创建一个tween序列
        Answer.SetDelay(Delay);
        Answer.Insert(0, TweenerY);//垂直版本：先播放Y轴缩放
        Answer.Insert(0.12f * Speed, TweenerX);//然后播放X轴缩放
        Answer.onComplete = Complete;
        return Answer;
    }

    public static Tween DOCloseVerticalTelevision(this Transform transform, float Speed = 1, TweenCallback Complete = null, float Delay = 0)
    {
        Tweener TweenerX = transform.DOScaleX(0, 0.27f * Speed);
        TweenerX.SetEase(Ease.OutExpo);
        Tweener TweenerY = transform.DOScaleY(0, 0.17f * Speed);
        TweenerY.SetEase(Ease.OutExpo);
        Sequence Answer = DOTween.Sequence();
        Answer.SetDelay(Delay);
        Answer.Insert(0, TweenerX);//垂直版本：先收缩X轴
        Answer.Insert(0.12f * Speed, TweenerY);//然后收缩Y轴
        Answer.onComplete = Complete;
        return Answer;
    }

    public static void ResetTelevision(this Transform transform)
    {
        transform.DOKill();
        transform.localScale = Vector3.zero;
    }
    #endregion
}